package com.example.validatestudy.demos.tread.sync;

public class SynchronizedTest{
    /**
     * synchronized
     * @param args
     */
    public static void main(String[] args) {
        // synchronized修饰代码块，锁的是实例对象r
        codeBlockTest();
    }

    public static void codeBlockTest(){
        Runnable r = new Runnable(){
            int flag = 1;
            @Override
            public void run(){
                synchronized (this){
                    System.out.println("this指的是实例对象r-"+this.flag);
                }
            }
        };
        try {
            Thread t = new Thread(r);
            t.start();
            t.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
